import routes from '@/router/routes'
function getFlatMenuList(menuList) {
  const newMenuList = JSON.parse(JSON.stringify(menuList))
  return newMenuList.flatMap(item => [item, ...(item.children ? getFlatMenuList(item.children) : [])])
}
const state = {
  menuList: []
}
const mutations = {
  getMenuList(state, list) {
    state.menuList = list
  }
}
const actions = {
  getMenuListApi(content) {
    content.commit('getMenuList', routes)
  }
}

const getters = {
  flatMenuListGet: state => getFlatMenuList(state.menuList)
}

export default {
  state,
  mutations,
  actions,
  getters
}
